package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.query.RegionQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//区域后端控制器
@RequestMapping("/region")
@Controller
public class RegionController {

    @Autowired
    private IRegionService regionService;

    @Autowired
    private IDestinationService destinationService;

    /**
     * 高查
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")RegionQuery qo) {
        Object page = regionService.query(qo);
        model.addAttribute("page",page);
        return "/region/list";
    }

    /**
     * 提供所有目的地数据(给保存或编辑下拉框提供数据)
     * @return
     */
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests() {
        return destinationService.findAll();
    }

    /**
     * 提供所有城市数据(给保存或编辑下拉框提供数据)
     * @return
     */
    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep) {
        return destinationService.findDestByDeep(deep);
    }

    /**
     * 保存或修改
     * @param region
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region) {
        regionService.saveOrUpdate(region);
        return JsonResult.success();
    }

    /**
     * 获取区域关联的城市
     * @param rid
     * @return
     */
    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(String rid) {
        return destinationService.getDestByRegionId(rid);
    }

    /**
     * 热门设置
     * @param id
     * @param hot
     * @return
     */
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(String id,String hot) {
        return regionService.changeHotValue(id,hot);
    }

    /**
     * 删除功能
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        regionService.delete(id);
        return JsonResult.success();
    }

}
